import { Options, Vue } from 'vue-class-component'
import navigator from '@/components/common/navigator.vue'
import store from '@/store'
import router from '@/router'
import component from '*.vue'

interface IShoppingMallParams {
  commodityId: string
}

@Options({
  components: {
    navigator
  }
})

export default class home extends Vue {
  goodsArr: any[] = []
  goodsDetail: any = null
  imgArr = [{
    id: 0,
    idView: require('@/assets/home/advertisement1.jpg')
  }, {
    id: 1,
    idView: require('@/assets/home/advertisement2.jpg')
  }, {
    id: 2,
    idView: require('@/assets/home/advertisement3.jpg')
  }]

  shoppingMallParams: IShoppingMallParams = {
    commodityId: ''
  }

  created () {
    store.dispatch('displayGoods').then(response => {
      this.goodsArr = response.data.data
      console.log(this.goodsArr)
    })
  }

  checkDetail (e
    :
    string
  ) {
    this.shoppingMallParams.commodityId = e
    let code
    let goodsDetail
    let goodsName
    let goodsPrice
    let goodsDes
    let goodsUpTime
    let userName
    let userDes
    store.dispatch('CheckGoodsDetail', this.shoppingMallParams).then(response => {
      console.log('connect success')
      goodsDetail = response.data.data
      this.goodsDetail = goodsDetail
      goodsName = this.goodsDetail.commodityName
      goodsPrice = this.goodsDetail.commodityPrice
      goodsDes = this.goodsDetail.commodityDescription
      goodsUpTime = this.goodsDetail.commodityUploadTime
      store.dispatch('CheckUserName', this.shoppingMallParams).then(response => {
        userName = response.data.data
        store.dispatch('CheckUserDes', this.shoppingMallParams).then(response => {
          userDes = response.data.data
          store.dispatch('UpdatePV', this.shoppingMallParams).then(response => {
            code = response.data.code
            if (code === 200) {
              router.push({
                path: '/goodsDetail',
                query: {
                  name: goodsName,
                  price: goodsPrice,
                  des: goodsDes,
                  uptime: goodsUpTime,
                  username: userName,
                  userdes: userDes
                }
              })
            }
          }).catch(() => {
            console.log('connect failed')
          })
        }).catch(() => {
          console.log('connect failed')
        })
      }).catch(() => {
        console.log('connect failed')
      })
    }).catch(() => {
      console.log('connect failed')
    })
  }
}
